package hmvictor.jpql.nodes;

import hmvictor.jpql.Connection;
import hmvictor.jpql.ConnectionsTopComponent;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JOptionPane;
import org.openide.nodes.Node;
import org.openide.windows.WindowManager;

/**
 *
 * @author Victor
 */
public class RemoveConnectionAction extends AbstractAction {
    private final Node node;

    public RemoveConnectionAction(Node node) {
        super("Remove");
        this.node=node;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (JOptionPane.showConfirmDialog(WindowManager.getDefault().getMainWindow(), "Are you sure you want to remove this connection?") == JOptionPane.OK_OPTION) {
            Connection connection = node.getLookup().lookup(Connection.class);
            ConnectionsTopComponent c=(ConnectionsTopComponent) WindowManager.getDefault().findTopComponent("ConnectionsTopComponent");
            c.removeConnection(connection.getName());
        }
    }

}
